import { _decorator, Component, Node, UITransform, Size, Slider } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('SliderActived')
export class SliderActived extends Component {
	pUI: UITransform;
	uiTransform: UITransform;
	sizeMax: Size = new Size();
	size: Size = new Size();
	start() {
		this.uiTransform = this.node.getComponent(UITransform);
		this.size.set(
			this.uiTransform.contentSize.x,
			this.uiTransform.contentSize.y
		);
		this.pUI = this.node.parent.getComponent(UITransform);
		this.sizeMax.set(this.pUI.contentSize);
	}
	setWidth(slider: Slider) {
		let progress = slider.progress;
		this.size.set(progress * this.sizeMax.x, this.size.y);
		this.uiTransform.setContentSize(this.size);
	}
	resetWidth() {
		this.size.set(31, this.size.y);
		this.uiTransform.setContentSize(this.size);
	}
}
